package cn.ibobo.lease.app.service.impl;

import cn.ibobo.lease.app.dao.GoodsMapper;
import cn.ibobo.lease.app.service.GoodsService;
import cn.ibobo.lease.common.base.BaseMapper;
import cn.ibobo.lease.common.base.BaseServiceImpl;
import cn.ibobo.lease.common.dto.GoodsDTO;
import cn.ibobo.lease.common.util.UuidUtil;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;


/**
 * 商品信息表业务处理接口
 * @Author lililiang
 * @Date 2018-12-13 18:38:03
 */
@Service
public class GoodsServiceImpl extends BaseServiceImpl<GoodsDTO, String> implements GoodsService {

    private static final Log LOGGER = LogFactory.getLog(GoodsServiceImpl.class);

    @Autowired
    private GoodsMapper mapper;

    @Override
    protected BaseMapper<GoodsDTO, String> getMapper() {
        return mapper;
    }

    /**
     * 商品信息表列表
     * @Author lililiang
     * @Date 2018-12-13 18:38:03
     * @Param
     * @Return
     */
    @Override
    public List<GoodsDTO> list4Page(GoodsDTO entity, Integer pageNum, Integer... pageSize) {
        return super.list4Page(entity, pageNum, pageSize);
    }

    /**
     * 商品信息表列表（无分页）
     * @Author lililiang
     * @Date 2018-12-13 18:38:03
     * @Param
     * @Return
     */
    @Override
    public List<GoodsDTO> listByCondition(GoodsDTO entity) {
        return super.listByCondition(entity);
    }

    /**
     * 查询商品信息表详情信息
     * @Author lililiang
     * @Date 2018-12-13 18:38:03
     * @Param
     * @Return
     */
    @Override
    public GoodsDTO queryOneByPk(String id) {
        return super.queryOneByPk(id);
    }

    /**
     * 保存商品信息表信息
     * @Author lililiang
     * @Date 2018-12-13 18:38:03
     * @Param
     * @Return
     */
    @Override
    @Transactional
    public Integer save(GoodsDTO entity) {
        String gid = entity.getGid();
        if(gid == null || gid.length() == 0){
            entity.setGid(UuidUtil.getUuid());
            return mapper.add(entity);
        }else{
            return mapper.edit(entity);
        }
    }

    /**
     * 删除商品信息表信息
     * @Author lililiang
     * @Date 2018-12-13 18:38:03
     * @Param
     * @Return
     */
    @Override
    @Transactional
    public Integer delete(String id) {
        return super.delete(id);
    }
}
